package cn.tedu.uep.message.service.impl;

import cn.tedu.uep.common.MessageConstants;
import cn.tedu.uep.message.po.dto.MessageCreateParam;
import cn.tedu.uep.message.po.vo.MessageVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.tedu.uep.message.po.entity.Message;
import cn.tedu.uep.message.service.MessageService;
import cn.tedu.uep.message.mapper.MessageMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author Administrator
* @description 针对表【message】的数据库操作Service实现
* @createDate 2024-12-18 15:57:27
*/
@Service
public class MessageServiceImpl implements MessageService{
    @Autowired
    MessageMapper messageMapper;

    /**
     * 查询消息
     */
    @Override
    public List<MessageVO> select(Long userId,String messageStatus) {
        return messageMapper.selectList(userId,messageStatus);
    }

    /**
     * 创建消息
     */
    @Override
    public Boolean createMessage(MessageCreateParam param) {
        Message message = new Message();
        BeanUtils.copyProperties(param,message);
        message.setCreateTime(new Date());
        message.setMessageStatus(MessageConstants.MESSAGE_STATUS_UNREAD);

        return messageMapper.createMessage(message);
    }

    /**
     * 已读消息（批量操作）
     */
    @Override
    public Boolean readMessage(List<Long> messageIds) {
        //批量更新状态，对状态进行赋值
        String messageStatus = MessageConstants.MESSAGE_STATUS_READ;
        return messageMapper.updateByList(messageIds, messageStatus);
    }
}




